﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using System;

namespace PlainObject_Mock
{
    public class MyClass
    {
        string _myString;
        public string MyProperty
        {
            get
            {
                return _myString + "YY";
            }

            set
            {
                _myString = value;
            }
        }
    }

    [TestClass]
    public class Test
    {
        [TestMethod]
        public void Method()
        {
            Mock<MyClass> myClass = new Mock<MyClass>();
            
            myClass.Object.MyProperty = "XX ";

            Console.Write("MY STRING IS:" + myClass.Object.MyProperty);
            //Although Mock, it actually works like the instance object
            //MY STRING IS:XX YY
        }

    }
}

namespace Object_With_Virtual_Member
{
    public class MyClass
    {
        string _myString;
        public virtual string MyProperty
        {
            get
            {
                return _myString + "YY";
            }

            set
            {
                _myString = value;
            }
        }
    }

    [TestClass]
    public class Test
    {
        [TestMethod]
        public void Method()
        {
            Mock<MyClass> myClass = new Mock<MyClass>();

            myClass.Object.MyProperty = "XX ";

            Console.Write("MY STRING IS:" + myClass.Object.MyProperty);
            //Although Mock, it actually works like the instance object
            //MY STRING IS:
        }

    }
}

namespace Object_With_Virtual_Member_And_Setup
{
    public class MyClass
    {
        string _myString;
        public virtual string MyProperty
        {
            get
            {
                return _myString + "YY";
            }

            set
            {
                _myString = value;
            }
        }
    }

    [TestClass]
    public class Test
    {
        [TestMethod]
        public void Method()
        {
            Mock<MyClass> myClass = new Mock<MyClass>();

            //myClass.Object.MyProperty = "XX "; meaningless here
            myClass.Setup(x => x.MyProperty).Returns("AA");
            Console.Write("MY STRING IS:" + myClass.Object.MyProperty);
            //Although Mock, it actually works like the instance object
            //MY STRING IS:AA
        }

    }
}